package org.example.commonUtils;

import java.util.concurrent.CountDownLatch;

/**
 * 辅助类： 减法计数器
 * 功能：指定线程执行完后，再执行后续操作
 */
public class CountDownLatchDemo {

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 0; i < 5; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName());
                countDownLatch.countDown(); // 数量 -1
            },String.valueOf(i)).start();
        }

        // 阻塞，等待计数为0
        countDownLatch.await();
        // 执行后续方法
        System.out.println("close the door");
    }
}

